package com.sljy.hzk.util;

import com.google.gson.Gson;
import com.sljy.hzk.entity.TaskDetailEntity;
import com.sljy.hzk.entity.TaskEntity;

import java.util.List;

/**
 * 保存本地数据用于离线执行
 * */
public class SaveDataUtils {

    public static enum dataType {
        TASK,//任务
        HARM,//危害因素
    }

    private String fileName = "hzkdata.txt";
    private OffLineInfo offLineInfo = new OffLineInfo();

    /**
     * 保存我的任务数据
     * */
    public void SaveTaskData(List<TaskEntity> taskList, List<TaskDetailEntity> TaskDetailList){
        Gson gson = new Gson();
        String t = gson.toJson(taskList);
        String d = gson.toJson(TaskDetailList);
        offLineInfo.TaskData = t;
        offLineInfo.TaskDetailData = d;
        String f = gson.toJson(offLineInfo);
        try {
            FileOperationUtils.writeTxtFile(f,fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 保存危害因素检测
     * */
    public void SaveHarmData(){

    }

    /**
     *读取数据
     * */
    public OffLineInfo ReadData() throws Exception {
        String data = FileOperationUtils.readTxtFile(fileName);
        Gson gson = new Gson();
        offLineInfo = gson.fromJson(data, OffLineInfo.class);
        return offLineInfo;
    }
}
/**
 * 基础数据
 * */
class OffLineInfo{
    //任务主体
    public String TaskData = null;
    //任务详情
    public String TaskDetailData = null;
    //危害因素检测主体
    public String HramData = null;
    //危害因素检测详情
    public String HramDetailData = null;
}
